package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizRaffleActivityPrize;
import com.member.shop.domain.SysBizRaffleQuota;
import com.member.shop.service.ISysBizRaffleQuotaService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【抽奖额度】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-11-09
 **/
@RestController
@RequestMapping("/shop/raffleQuota")
public class SysBizRaffleQuotaController extends BaseController {
    @Resource
    private ISysBizRaffleQuotaService sysBizRaffleQuotaService;

    private void setTenantId(SysBizRaffleQuota sysBizRaffleQuota) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizRaffleQuota.setTenantId(tenantId);
        }
    }

    /**
     * 查询抽奖额度列表
     */
    @PreAuthorize("@ss.hasPermi('shop:raffleQuota:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizRaffleQuota sysBizRaffleQuota) {
        startPage();
        setTenantId(sysBizRaffleQuota);
        List<SysBizRaffleQuota> list = sysBizRaffleQuotaService.selectSysBizRaffleQuotaList(sysBizRaffleQuota);
        return getDataTable(list);
    }

    /**
     * 导出抽奖额度列表
     */
    @PreAuthorize("@ss.hasPermi('shop:raffleQuota:export')")
    @Log(title = "抽奖额度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizRaffleQuota sysBizRaffleQuota) {
        setTenantId(sysBizRaffleQuota);
        List<SysBizRaffleQuota> list = sysBizRaffleQuotaService.selectSysBizRaffleQuotaList(sysBizRaffleQuota);
        ExcelUtil<SysBizRaffleQuota> util = new ExcelUtil<SysBizRaffleQuota>(SysBizRaffleQuota.class);
        util.exportExcel(response, list, "抽奖额度数据");
    }

    /**
     * 获取抽奖额度详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:raffleQuota:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizRaffleQuotaService.selectSysBizRaffleQuotaById(id));
    }

    /**
     * 新增抽奖额度
     */
    @PreAuthorize("@ss.hasPermi('shop:raffleQuota:add')")
    @Log(title = "抽奖额度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizRaffleQuota sysBizRaffleQuota) {
        return toAjax(sysBizRaffleQuotaService.insertSysBizRaffleQuota(sysBizRaffleQuota));
    }

    /**
     * 修改抽奖额度
     */
    @PreAuthorize("@ss.hasPermi('shop:raffleQuota:edit')")
    @Log(title = "抽奖额度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizRaffleQuota sysBizRaffleQuota) {
        return toAjax(sysBizRaffleQuotaService.updateSysBizRaffleQuota(sysBizRaffleQuota));
    }

    /**
     * 删除抽奖额度
     */
    @PreAuthorize("@ss.hasPermi('shop:raffleQuota:remove')")
    @Log(title = "抽奖额度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizRaffleQuotaService.deleteSysBizRaffleQuotaByIds(ids));
    }
}
